package com.zyh.house.controller;

import com.zyh.common.annotation.Log;
import com.zyh.common.core.controller.BaseController;
import com.zyh.common.core.domain.AjaxResult;
import com.zyh.common.core.page.TableDataInfo;
import com.zyh.common.enums.BusinessType;
import com.zyh.common.utils.poi.ExcelUtil;
import com.zyh.house.domain.HouseInfo;
import com.zyh.house.service.IHouseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房源管理Controller
 * 
 * @author zyh
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/house/house")
public class HouseInfoController extends BaseController
{
    @Autowired
    private IHouseInfoService houseInfoService;

    /**
     * 查询房源管理列表
     */
    @PreAuthorize("@ss.hasPermi('house:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseInfo houseInfo)
    {
        startPage();
        List<HouseInfo> list = houseInfoService.selectHouseInfoList(houseInfo);
        return getDataTable(list);
    }

    /**
     * 导出房源管理列表
     */
    @PreAuthorize("@ss.hasPermi('house:house:export')")
    @Log(title = "房源管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseInfo houseInfo)
    {
        List<HouseInfo> list = houseInfoService.selectHouseInfoList(houseInfo);
        ExcelUtil<HouseInfo> util = new ExcelUtil<HouseInfo>(HouseInfo.class);
        util.exportExcel(response, list, "房源管理数据");
    }

    /**
     * 获取房源管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('house:house:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(houseInfoService.selectHouseInfoById(id));
    }

    /**
     * 新增房源管理
     */
    @PreAuthorize("@ss.hasPermi('house:house:add')")
    @Log(title = "房源管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseInfo houseInfo)
    {
        return toAjax(houseInfoService.insertHouseInfo(houseInfo));
    }

    /**
     * 修改房源管理
     */
    @PreAuthorize("@ss.hasPermi('house:house:edit')")
    @Log(title = "房源管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseInfo houseInfo)
    {
        return toAjax(houseInfoService.updateHouseInfo(houseInfo));
    }

    /**
     * 删除房源管理
     */
    @PreAuthorize("@ss.hasPermi('house:house:remove')")
    @Log(title = "房源管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(houseInfoService.deleteHouseInfoByIds(ids));
    }
}
